#include<cstring>
#include<cerrno>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<iostream>
#include"common.h"

using namespace std;

int main()
{
    //客户端
    //1. 打开文件
    int wfd=open(fifo_name.c_str(),O_WRONLY);
    if(wfd < 0)
    {
        cerr << "open fail! errno: " << errno << " | " << strerror(errno) << endl;
        exit(0);
    }

    // 2. 写入数据，进行通信
    char buff[64]={0};
    while(true)
    {
        cout<<"Client send message# ";
        fgets(buff,sizeof(buff)-1,stdin);
        buff[strlen(buff)-1]='\0'; //去除换行

        if(strcasecmp("exit", buff) == 0)
          break;

        write(wfd,buff,strlen(buff));
    }

    close(wfd);

    return 0;
}